package com.fcat.common.fdfs.config;


import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import tk.mybatis.spring.mapper.MapperScannerConfigurer;


@Configuration
@AutoConfigureAfter(MybatisConfiguration.class)
public class MapperConfiguration implements EnvironmentAware {


    private String basePackage;

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer(Environment environment){

        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
        mapperScannerConfigurer.setBasePackage(basePackage);

        /*MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory");
        mapperScannerConfigurer.setBasePackage(basePackage);//普通mapper的位置

        Properties properties = new Properties();
        properties.setProperty("mappers", TsuantoneBaseMapper.class.getName());//通用mapper的全名
        properties.setProperty("notEmpty", "false");
        properties.setProperty("IDENTITY", "MYSQL");//配置数据库方言

        mapperScannerConfigurer.setProperties(properties);*/

        return mapperScannerConfigurer;
    }


    public void setEnvironment(Environment environment) {
        this.basePackage = environment.getProperty("mybatis.basepackage");
    }
}